package com.ruoyi.zsyh.controller;

import java.util.List;

import com.ruoyi.zsyh.domain.SysDtArea;
import com.ruoyi.zsyh.service.ISysDtAreaService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.zsyh.domain.ZsyhPersonOrder;
import com.ruoyi.zsyh.service.IZsyhPersonOrderService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 个人扫码单Controller
 * 
 * @author yuexl
 * @date 2024-08-22
 */
@Controller
@RequestMapping("/zsyh/personOrder")
public class ZsyhPersonOrderController extends BaseController
{
    private String prefix = "zsyh/personOrder";

    @Autowired
    private IZsyhPersonOrderService zsyhPersonOrderService;
    @Autowired
    private ISysDtAreaService sysDtAreaService;

    @RequiresPermissions("zsyh:personOrder:view")
    @GetMapping()
    public String personOrder()
    {
        return prefix + "/personOrder";
    }

    /**
     * 获取省
     */
    @GetMapping("/{parentId}")
    @ResponseBody
    public TableDataInfo provinceData(@PathVariable("parentId") String parentId)
    {
        SysDtArea sysDtArea1 = new SysDtArea();
        sysDtArea1.setAreaParentId(parentId);
        return  getDataTable(sysDtAreaService.selectSysDtAreaList(sysDtArea1));
    }

    /**
     * 查询个人扫码单列表
     */
    @RequiresPermissions("zsyh:personOrder:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZsyhPersonOrder zsyhPersonOrder)
    {
        startPage();
        List<ZsyhPersonOrder> list = zsyhPersonOrderService.selectZsyhPersonOrderList(zsyhPersonOrder);
        return getDataTable(list);
    }

    /**
     * 导出个人扫码单列表
     */
    @RequiresPermissions("zsyh:personOrder:export")
    @Log(title = "个人扫码单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZsyhPersonOrder zsyhPersonOrder)
    {
        List<ZsyhPersonOrder> list = zsyhPersonOrderService.selectZsyhPersonOrderList(zsyhPersonOrder);
        ExcelUtil<ZsyhPersonOrder> util = new ExcelUtil<ZsyhPersonOrder>(ZsyhPersonOrder.class);
        return util.exportExcel(list, "个人扫码单数据");
    }

    /**
     * 新增个人扫码单
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存个人扫码单
     */
    @RequiresPermissions("zsyh:personOrder:add")
    @Log(title = "个人扫码单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZsyhPersonOrder zsyhPersonOrder)
    {
        return toAjax(zsyhPersonOrderService.insertZsyhPersonOrder(zsyhPersonOrder));
    }

    /**
     * 修改个人扫码单
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        ZsyhPersonOrder zsyhPersonOrder = zsyhPersonOrderService.selectZsyhPersonOrderById(id);
        mmap.put("zsyhPersonOrder", zsyhPersonOrder);
        return prefix + "/edit";
    }

    /**
     * 修改保存个人扫码单
     */
    @RequiresPermissions("zsyh:personOrder:edit")
    @Log(title = "个人扫码单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZsyhPersonOrder zsyhPersonOrder)
    {
        return toAjax(zsyhPersonOrderService.updateZsyhPersonOrder(zsyhPersonOrder));
    }

    /**
     * 删除个人扫码单
     */
    @RequiresPermissions("zsyh:personOrder:remove")
    @Log(title = "个人扫码单", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zsyhPersonOrderService.deleteZsyhPersonOrderByIds(ids));
    }

    /**
     * 查看报修图片
     */
    @GetMapping("/viewProof/{id}")
    public String viewProof(@PathVariable("id") String id, ModelMap mmap)
    {
        ZsyhPersonOrder zsyhPersonOrder = zsyhPersonOrderService.selectZsyhPersonOrderById(id);
        mmap.put("zsyhPersonOrder", zsyhPersonOrder);
        return prefix + "/viewProof";
    }


}
